// Copyright 2022 a.o.smith ALL Rights Reserved
package com.liuxinlong.modules.dao.impl;

import com.liuxinlong.modules.dao.PatentDepartmentDao;
import com.liuxinlong.modules.entity.PatentDepartment;
import com.liuxinlong.modules.mapper.PatentDepartmentMapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 类描述
 * <p>
 * 此类关联设计的功能
 *
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2023年9月1日
 */
@Service
public class PatentDepartmentDaoImpl extends ServiceImpl<PatentDepartmentMapper, PatentDepartment> implements PatentDepartmentDao {

	@Override
	public List<PatentDepartment> pageDepartmentList(Map<String, Object> queryParam) {
		return baseMapper.pageDepartmentList(queryParam);
	}

	@Override
	public int getDepartmentCount(Map<String, Object> queryParam) {
		return baseMapper.getDepartmentCount(queryParam);
	}

	@Override
	public Map<String, Map<String, String>> getDepartmentMap() {
		return baseMapper.getDepartmentMap();
	}

	@Override
	public List<PatentDepartment> getDepartmentList() {
		return baseMapper.getDepartmentList();
	}

	@Override
	public PatentDepartment getDepartmentByName(String departmentName) {
		return baseMapper.getDepartmentByName(departmentName);
	}

	@Override
	public PatentDepartment getDepartmentBySn(String sn) {
		return baseMapper.getDepartmentBySn(sn);
	}

	@Override
	public PatentDepartment getDepartmentByChild(String childId) {
		return baseMapper.getDepartmentByChild(childId);
	}

	@Override
	public Map<String, Map<String, String>> getDepartmentMapBySn() {
		return baseMapper.getDepartmentMapBySn();
	}

	@Override
	public List<PatentDepartment> getDepartmentByManager(String userId) {
		return baseMapper.getDepartmentByManager(userId);
	}

	@Override
	public Map<String, Map<String, String>> getDepartmentMapByName() {
		return baseMapper.getDepartmentMapByName();
	}

	@Override
	public Map<String, String> getDepartmentBranchMap() {
		List<PatentDepartment> departmentList = baseMapper.getDepartmentList();
		Map<String, String> branchMap = new HashMap<>();
		for (PatentDepartment dep : departmentList) {
			if (StringUtils.isEmpty(dep.getBranch())) {
				continue;
			}
			List<String> branchList = Arrays.asList(dep.getBranch().split(","));
			for (String branch : branchList) {
				branchMap.put(branch,dep.getId());
			}
		}
		return branchMap;
	}

	@Override
	public List<PatentDepartment> getDepartmentByDutyUser(String userId) {
		return baseMapper.getDepartmentByDutyUser(userId);
	}

}
